class UserNotifier < ActionMailer::Base
  @@url = "http://volunteers.transformativeworks.org/"
  @@from = "otwdb-do-not-reply@transformativeworks.org"
  
  def self.set_url(url)
    @@url = url
  end

  def self.get_url
    @@url
  end

  def self.set_from(from)
    @@from = from
  end
  
  def self.get_from
    @@from
  end
  
  def signup_notification(user)
    setup_email(user)
    @subject    += 'Please activate your new account!'
    @body[:url] += "user/activate/#{user.activation_code}"
  end
  
  def activation(user)
    setup_email(user)
    @subject    += 'Your account has been activated!'
  end

  def job_posting_notification(job)
    setup_email_without_user
    @recipients = "volunteers@transformativeworks.org"
    @body[:job] = job
  end

  def job_possibility_notification(user, job)
    setup_email(user)
    @body[:job] = job
    @body[:url] += "job/show/#{job.id}"
  end

  def assignment_notification(user, job)
    setup_email(user)
    @subject    += "Volunteer Assignment"
    @body[:job]  = job
    @body[:url]  += "job/show/#{job.id}"
  end
  
  
  protected
  
  def setup_email_without_user
    @from        = @@from
    @subject     = "[OTW Volunteers DB] "
    @sent_on     = Time.now
    @body[:url]  = @@url    
  end
  
  def setup_email(user)
    setup_email_without_user
    @recipients  = "#{user.email}"
    @body[:user] = user    
  end
end
